package concurrent;

public class VolatileTest {

    static class Counter {
        private volatile int count = 0;

        public void addCount() {
            this.count++;
            System.out.println(Thread.currentThread().getName()+",count:"+this.count);
        }

        public void decreCount() {
            this.count--;
        }

    }


    static class ModifyCount implements Runnable {

        public Counter counter;

        public ModifyCount(Counter counter) {
            this.counter = counter;
        }

        @Override

        public void run() {
            counter.addCount();
        }

    }

    public static void main(String[] args) {

        Counter c = new Counter();
//        Thread t2 = new Thread(new ModifyCount(c));
//        t2.setName("thread2");
//        t2.start();

        for (int i = 0; i < 50; i++) {
            Thread t = new Thread(new ModifyCount(c));
            t.setName("thread"+i);
            t.start();

        }
    }


}
